<?php
// 本文档自动生成，仅供测试运行
class ItemAction extends BaseAction
{
    /**
    +----------------------------------------------------------
    * 默认操作
    +----------------------------------------------------------
    */
    public function index()
    {
        //$NbSite	= M("User");
		//$strJumpUrl = APP_NAME."://Mmp/";
		//var_dump(U($strJumpUrl));
		/*import("@.ORG.Page"); //导入分页类
                $count = $NbSite->count();    //计算总数
                $p = new Page ( $count, 5 );
		$list=$NbSite->limit($p->firstRow.','.$p->listRows)->order('site_id desc')->select();
		$p->setConfig('header','个网站');
		$p->setConfig('prev',"[上一页]");
		$p->setConfig('next','[下一页]');
		$p->setConfig('first','[第一页]');
		$p->setConfig('last','[末页]');
		$page = $p->show ();*/
		//$this->assign( "page", $page );
		//$this->assign ( "list", $list );
		//$this->display();
		$Item = M("Item");
		$count = $Item->where("item_flag = 1")->count();
		$pagesize = 20;
		import("ORG.Util.Page");
		$p = new Page($count,$pagesize);
		$arrRow = $Item->limit($p->firstRow.','.$p->listRows)->where("item_flag = 1")->order("item_cdate desc")->select();
		$p->setConfig('header','个愿望');
		$p->setConfig('prev','<');
		$p->setConfig('next','>');
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('theme', ' <span>%nowPage%/%totalPage% 页 </span> %first% %upPage% %linkPage% %downPage% %end%');
		$page = $p->show(1);
		$this->assign( "page", $page );
		$this->assign( "item_list", $arrRow );
		$this->display();
        
    }
	

	public function additem()
	{
		
		$Form	=	D("Item");
		if($Form->create()) 
		{
			if(false !==$Form->add()) 
			{
    			$this->success('提交成功');
            }
			else
			{
                $this->error('提交失败');
            }
		}
		else
		{
			$this->error($Form->getError());
		}
	}
	
	public function modifyitem()
	{
            if($_POST['action']!='modify')
            {
                $Item = M('Item');
		$id = intval($_GET['itemid']);
		$row = $Item->where("item_id = $id")->find();
		$this->assign( "item_title", $row['item_title'] );
		$this->assign( "item_content", $row['item_content'] );
                $this->assign('item_id', $row['item_id']);
		$this->display();
            }
            else
            {
                if(!empty($_FILES['imgfile']['name']))
                {
			import("ORG.Net.UploadFile");
			$upload = new UploadFile();
			$upload->maxSize  = 3145728 ; 
			$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg'); 
			$upload->savePath =  './Public/Upload/images/';
			$upload->saveRule = 'uniqid';
			$upload->thumb = true;
			$uplocd->thumbPath  =  './Public/Upload/images/';
			$upload->subType = 'date';
			$upload->thumbMaxWidth = 100;
			$upload->thumbMaxHeight = 100;
			$upload->uploadReplace = true;
			$upload->thumbPrefix = '';
			$upload->thumbSuffix = '.small.jpg';
			$upload->autoSub = true;
			if(!$upload->upload()) { 
				$this->error($upload->getErrorMsg());
			}else{
				$imgs = $upload->getUploadFileInfo(); 
				//$model->img = 'Upload/images/'.$imgs[0]['savename'];
                                $filename =  'Upload/images/'.$imgs[0]['savename'];
			}
		}
                $data['item_title'] = trim($_POST['item_title']);
                $data['item_content'] = $_POST['item_content'];
                $data['item_simg'] = $filename;
                $id = $_POST['item_id'];
                $item = M('Item');
                $item->where(" item_id = $id ")->data($data)->save();
            }
                
	}
        
     
    /**
    +----------------------------------------------------------
    * 探针模式
    +----------------------------------------------------------
    */
    public function checkEnv()
    {
        load('pointer',THINK_PATH.'/Tpl/Autoindex');//载入探针函数
        $env_table = check_env();//根据当前函数获取当前环境
        echo $env_table;
    }

}
?>